<style lang="less" scoped>
/deep/.el-dialog--center .el-dialog__body {
    padding: 20px 10px 28px !important;
}

/deep/.el-form-item__label {
    padding-right: 0;
}

.patient-info {
    table tr th {
        font-weight: bold
    }

    table,
    table tr th,
    table tr td {
        border: 1px solid #EBEEF5;
    }

    table {
        width: 100%;
        min-height: 40px;
        line-height: 40px;
        text-align: center;
        border-collapse: collapse;
        padding: 2px;
    }
}
</style> 

<template>
    <el-dialog v-el-drag-dialog title="影像匹配" :visible.sync="matchImageShow" :before-close="MatchClose" width="1100px" top="3%" center>
        <div class="of">
            <div class="patient-info">
                <div class="mb5"> <strong >影像信息</strong></div>
               

                <table>
                    <tr>
                        <th class="w97">患者编号</th>
                        <th class="w80">患者姓名</th>
                        <th class="w30">性别</th>
                        <th class="w56">检查类型</th>
                        <th class="w97">检查编号</th>
                        <th class="w80">检查日期</th>
                        <th class="w56">序列数</th>
                        <th class="w56">实例数</th>

                    </tr>
                    <tr>
                        <td>{{ oldImageData.patient_id }}</td>
                        <td>{{ oldImageData.other_patient_name ? oldImageData.other_patient_name :
                            oldImageData.patient_name }}</td>
                        <td>{{ oldImageData.patient_sex | sexFilters }}</td>
                        <td>{{ oldImageData.modalities_in_study }}</td>
                        <td>{{ oldImageData.accession_number }}</td>
                        <td>{{ oldImageData.study_date_time }}</td>
                        <td>{{ getSeriesCount }}</td>
                        <td>{{ getImageCount }}</td>

                    </tr>
                </table>
            </div>
            <div class="tc mt10 mb10">
                <i class="iconfont clr_0a70b0" style="font-size: 28px">&#xe676a;</i>
            </div>
            <div class="patient-info">
                <div class="mb5"><strong class="mb10">检查信息</strong></div>
              

                <table>
                    <tr>
                        <th class="w97">患者编号</th>
                        <th class="w80">患者姓名</th>
                        <th class="w30">性别</th>
                        <th class="w56">检查类型</th>
                        <th class="w97">检查编号</th>
                        <th class="w80">检查日期</th>
                        <th class="w112">检查项目</th>
                    </tr>
                    <tr>
                        <td>{{ matchImageData.patient_id }}</td>
                        <td>{{ matchImageData.patient_name }}</td>
                        <td>{{ matchImageData.patient_sex | sexFilters }}</td>
                        <td>{{ matchImageData.modalities_in_study }}</td>
                        <td>{{ matchImageData.accession_number }}</td>
                        <td>{{ matchImageData.reg_time }}</td>
                        <td>{{ matchImageData.examination_item_name }}</td>
                    </tr>
                </table>
            </div>
            <el-alert :title="alertTitle" type="warning" center show-icon class="mt10 mb30" :closable="false">
            </el-alert>
            <div slot="footer" class="dialog-footer fr">
                <el-button @click="MatchClose" size="medium" class="mr20">取 消</el-button>
                <el-button type="primary" @click="MatchSubmit" size="medium">确 定</el-button>
            </div>
        </div>
    </el-dialog>
</template>
<script>
export default {
    data() {
        return {
            timeId: null,
            alertTitle:'确定要进行影像匹配吗？',
        }
    },

    props: ['matchImageShow', 'matchImageData', 'oldImageData', 'oldSeriesData'],
    filters: {
        sexFilters(val) {
            if (val) {
                if (val === 'M' || val === '男') {
                    return '男'
                } else if (val === 'F' || val === '女') {
                    return '女'
                }
            } else {
                return ''
            }
        },

    },
    
    computed: {
        getSeriesCount() {
            return this.oldSeriesData.length
        },
        getImageCount() {
            return this.oldSeriesData.reduce((totalVal, currentVal) => {
                return totalVal + currentVal.images_count
            }, 0)
        }
    },
    watch:{
        oldImageData(newVal){
            if(newVal){
                this.alertTitle = newVal.match_state === 1 ? '检查可能已用于书写报告，请及时通知报告医生！':'确定要进行影像匹配吗？'
            }
        }
    },
    methods: {


        timestampNowTime() {
            let nowTime = new Date()
            let times = nowTime.toLocaleString('en-US', { hour12: false }).split(" ")
            let time = times[1]
            let mdy = times[0]
            mdy = mdy.split('/')
            let month = parseInt(mdy[0]);
            let day = parseInt(mdy[1]);
            let year = parseInt(mdy[2])
            return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day) + ' ' + time
        },


        MatchClose(val) {

            this.$emit('MatchClose', val)
        },
        async MatchSubmit() {

            //提交影像拆分数据
            this.loading = this.$loading({
                lock: true,
                text: '匹配中...',
                spinner: 'el-icon-loading',
            });

            const params = {
                ...this.matchImageData,
                // report_type:'',
                report_type: sessionStorage.getItem('currentSystemClass') === 'ECGIS' ? 'ECG' : sessionStorage.getItem('currentSystemClass')
            }
            this.$pacsApi.pacsApi.imgMatch(params, this.oldImageData.id).then(res => {
                let { code, msg } = res
                if (code === 0) {
                    this.$message({
                        type: 'success',
                        message: msg
                    })
                    this.loading.close();
                    this.MatchClose('true')
                } else {
                    this.$message.error(msg)
                    this.loading.close()
                }
            }, err => {
                this.loading.close();
            }).catch(error => {
                this.loading.close();
            })

        }
    }

}
</script>
